package com.yayo.mangement.utils;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CountDownLatch;

/**
 * @desc:
 * @author: yang
 * @date: 2022/9/6
 */
public class ThreadDemo implements Callback {

    @Override
    public void execute(Object obj) {
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(Thread.currentThread().getName() + "         " +obj);
    }


    public static void main(String[] args) {
        List<Map<String, String>> list = new ArrayList<>();
        for(int i = 0 ; i < 100; i ++){
            Map<String, String> map = new HashMap<>();
            map.put(i + "", i + "");
            list.add(map);
        }

        CountDownLatch countDownLatch = new CountDownLatch(list.size());
        for(Map<String,String> map : list){
            ThreadTask.execute(map, new ThreadDemo(),countDownLatch);
        }
        try {
            countDownLatch.await();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }finally {
            ThreadTask.pool.shutdown();
        }
        System.out.println("完成");
    }

}
